/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package editorRozpisu;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import strukturaRozpis.PocetHodinZam;
import strukturaRozpis.Rozpis;
import strukturaZamestnanciNepritomnost.Zamestnanci;

/**
 *
 * @author Marek
 */
public class Hodiny extends javax.swing.JFrame {

    Rozpis rozpis;

    /**
     * Creates new form Hodiny
     */
    public Hodiny(Rozpis r) {
        rozpis = r;
        initComponents();

        //centralizovanie okna
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int X = (screen.width / 2) - (this.getWidth() / 2); // Center horizontally.
        int Y = (screen.height / 2) - (this.getHeight() / 2); // Center vertically.
        this.setLocation(X, Y);

        TreeMap<Integer, PocetHodinZam> hodiny = r.getPocetHodinZamestnancov();

        showTable(hodiny);


        jLabel1.setText("Počet hodín pre vrátnika: " + rozpis.getPocetHodin(0));
        jLabel2.setText("Počet hodín pre strážnika: " + rozpis.getPocetHodin(1));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        jLabel1.setText("jLabel1");

        jLabel2.setText("jLabel2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Hodiny.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Hodiny.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Hodiny.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Hodiny.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                //new Hodiny().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    private void showTable(TreeMap<Integer, PocetHodinZam> hodiny) {
        try {
            DefaultTableModel myTabel = new DefaultTableModel();
            String headers[] = new String[7];
            headers[0] = "Meno";
            headers[1] = "normalne dni";
            headers[2] = "vikendy";
            headers[3] = "sviatky";
            headers[4] = "celkovo";
            headers[5] = "v noci";
            headers[6] = "cez den";
            myTabel.setColumnIdentifiers(headers);

            jTable1.setModel(myTabel);
            jTable1.getColumnModel().getColumn(0).setCellRenderer(new RendererTypZamestnanca());
            jTable1.getColumnModel().getColumn(4).setCellRenderer(new RendererPocetHodin(rozpis));

            Zamestnanci z = new Zamestnanci();

            Set<Integer> keySet = hodiny.keySet();
            int i = 0;
            for (Integer key : keySet) {
                myTabel.addRow(headers);
                myTabel.setValueAt(z.getZamestnanec(key).getPriezvisko() + " " + z.getZamestnanec(key).getMeno(), i, 0);
                myTabel.setValueAt(hodiny.get(key).getPocetCezNormaleDni(), i, 1);
                myTabel.setValueAt(hodiny.get(key).getPocetCezVikendy(), i, 2);
                myTabel.setValueAt(hodiny.get(key).getPocetCezSviatky(), i, 3);
                myTabel.setValueAt(hodiny.get(key).getCelkovyPocet(), i, 4);
                myTabel.setValueAt(hodiny.get(key).getPocetVNoci(), i, 5);
                myTabel.setValueAt(hodiny.get(key).getPocetCezDen(), i, 6);
                i++;
            }

        } catch (SQLException ex) {
            Logger.getLogger(Hodiny.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(Hodiny.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
